package org.gaaidou.ptarmigan.springboot.distributed.zk;

import org.apache.curator.framework.CuratorFramework;
import org.gaaidou.ptarmigan.springboot.distributed.DistributedLock;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.concurrent.locks.Lock;

@Component
public class ZkDistributedLock implements DistributedLock {
    @Autowired
    private CuratorFramework curatorFramework;

    public Lock create(String resource, int lockTimeoutSecond) {
        return new ZkLock(resource, lockTimeoutSecond, curatorFramework);
    }

    public Lock create(String resource) {
        return new ZkLock(resource, 20, curatorFramework);
    }
}
